package com.zipking.cloud.springbootmybatis.service;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Queues;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class DoorOpeningRecordTask extends Thread{
    @Autowired
    private RequestQueue requestQueue;

  /*  @Autowired
    private DoorOpeningRecordService doorOpeningRecordService;*/

    @Override
    public void run(){
        while(true){
            try {
                //取出信息列表
                List<JSONObject> list = new ArrayList<>();
                //参数列表： 获取队列  数据  批量处理一百条  500毫秒
                log.info("获取的数据:{}",requestQueue.getBlockingQueue());
                Queues.drain(requestQueue.getBlockingQueue(), list, 100, 500, TimeUnit.MILLISECONDS);
                //对数据进行保存
                log.info("--入库--");
                //doorOpeningRecordService.save(list);

            }catch (Exception e){
                e.printStackTrace();
            }

        }

    }


}
